package com.cykj.order.consumer;

/**
 * @BelongsProject: Cykj-Order-System
 * @BelongsPackage: com.cykj.order.consumer
 * @Author: cwx
 * @CreateTime: 2025/9/4 12:08
 * @Description:
 * @Version: 1.0
 */

import com.cykj.order.service.OrderBusinessService;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 订单超时消费者（监听RocketMQ延迟消息）
 */
@Component
@RocketMQMessageListener(
        topic = "order-timeout-topic",
        consumerGroup = "${rocketmq.consumer.group}", // 配置文件中的消费者组
        consumeMode = ConsumeMode.ORDERLY // 顺序消费，避免并发问题
)
public class OrderTimeoutConsumer implements RocketMQListener<Long> {

    @Autowired
    private OrderBusinessService orderBusinessService;

    @Override
    public void onMessage(Long orderId) {
        // 消费延迟消息，处理超时取消
        orderBusinessService.cancelOrderByTimeout(orderId);
    }
}
